#pragma once

#include<iostream>
#include<unistd.h>

typedef void(*work_t)(pid_t);
typedef void(*task_t)(pid_t);

void task_1(pid_t id)
{
    std::cout << "task_1" << std::endl;
}

void task_2(pid_t id)
{
    std::cout << "task_2" << std::endl;
}

void task_3(pid_t id)
{
    std::cout << "task_3" << std::endl;
}

task_t tasks[3] = {task_1, task_2, task_3};

void worker(int channel_index)
{
    while(1)
    {
        int task_index = 0;
        int n = read(0, &task_index, sizeof(int));
        if (0 == n)
        {
            std::cout << "write close, channel: " << channel_index << "closing" << std::endl; 
            break;
        }
           
        
        std::cout << "channel: " << channel_index << "  pid: " << getpid() << ": i am working: ";
        tasks[task_index](getpid());
    }
}